#include <boost/test/included/unit_test.hpp>
#include <boost/smart_ptr.hpp>
#include "arguments.h"

#include <cmath>

/*
 * // seven ways to detect and report the same error:
    BOOST_CHECK( add( 2,2 ) == 4 );        // #1 continues on error

    BOOST_REQUIRE( add( 2,2 ) == 4 );      // #2 throws on error

    if( add( 2,2 ) != 4 )
      BOOST_ERROR( "Ouch..." );            // #3 continues on error

    if( add( 2,2 ) != 4 )
      BOOST_FAIL( "Ouch..." );             // #4 throws on error

    if( add( 2,2 ) != 4 ) throw "Ouch..."; // #5 throws on error

    BOOST_CHECK_MESSAGE( add( 2,2 ) == 4,  // #6 continues on error
                         "add(..) result: " << add( 2,2 ) );

    BOOST_CHECK_EQUAL( add( 2,2 ), 4 );	  // #7 continues on error
 */

void test_arguments() {
	const double threshold = 0.1e6;
	boost::shared_ptr<Arguments> arguments = boost::shared_ptr<Arguments>(new Arguments);
	int argc = 3;
	char** argv;
	argv = new char*[argc];
	argv[0] = "/home/xuxiang/projects/facader/build/bin/facader_tests";
	argv[1] = "--workplace";
	argv[2] =	 "test_data";
	
	Status status = arguments->Parse(argc, argv);
	BOOST_REQUIRE(status.IsOk());
	
	BOOST_CHECK_EQUAL(arguments->GetRawFile(), "test_data/raw.ply");
	std::vector<double>& resample = arguments->GetSampleLeafSize();
	BOOST_CHECK(std::abs(resample[0] - 0.1) < threshold);
	BOOST_CHECK(std::abs(resample[1]- 0.2) < threshold);
	BOOST_CHECK(std::abs(resample[2]- 0.3) < threshold);
	
	std::vector<double>& radius_outlier = arguments->GetRadiusOutlierParameters();
	BOOST_CHECK(std::abs(radius_outlier[0]- 0.1) < threshold);
	BOOST_CHECK(std::abs(radius_outlier[1] - 5) < threshold);
	
	std::vector<double>& statistic_outlier = arguments->GetStatisticalOutlierParameters();
	BOOST_CHECK(std::abs(statistic_outlier[0] - 0.1) < threshold);
	BOOST_CHECK(std::abs(statistic_outlier[1]- 0.1) < threshold);
	
	BOOST_CHECK(std::abs(arguments->GetPlaneThreshold()- 0.1) < threshold);
	BOOST_CHECK(std::abs(arguments->GetResolution() - 0.1) < threshold);
	BOOST_CHECK_EQUAL(arguments->LoadSVMModel(), true);
	BOOST_CHECK_EQUAL(arguments->LoadQTable(), false);
	
	BOOST_CHECK(std::abs(arguments->GetLearningEpisodes() - 5000)  < threshold);
	BOOST_CHECK(std::abs(arguments->GetGreedyLearningEpisodes() - 1000)  < threshold);
	BOOST_CHECK(std::abs(arguments->GetLearningRate() - 1.0)  < threshold);
	BOOST_CHECK_EQUAL(arguments->StateGroup(), true);
	
	std::vector<double>& weights = arguments->GetSymbolWeights();
	BOOST_CHECK(std::abs(weights[0] - 0.5)  < threshold);
	BOOST_CHECK(std::abs(weights[1] - 0.5)  < threshold);
}